package MultiThreaded;

import java.util.Random;
import java.util.concurrent.Callable;

public class LoopCallable implements Callable<Double>{
	
	int nSteps, z;
	Double St, Drift, vSqrdt,X;
	Double Sum=0.0;
	
	

	public LoopCallable(int nSteps, Double st, Double drift, Double vSqrdt,
			int z2, Double x, Double sum) {
		super();
		this.nSteps = nSteps;
		St = st;
		Drift = drift;
		this.vSqrdt = vSqrdt;
		this.z = z2;
		X = x;
		Sum = sum;
	}


	//method called for each Callable thread to compute the calculation
	@Override
	public Double call() throws Exception {
		
		Random random=new Random();
		
		for(int j=0; j<nSteps; j++) {
			St = St * java.lang.Math.exp(Drift + vSqrdt * random.nextGaussian());
		}
		Sum = Sum + java.lang.Math.max (z* (St-X), 0);
	  
		
		return Sum;
	}

}
